{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8fd673c3",
   "metadata": {},
   "source": [
    "-----\n",
    "* 2022/09/13/week04\n",
    "* Python 课堂笔记\n",
    "---------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "dff4bc9e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 上周回顾（range() ) \n",
    "range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2bc4dfb4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, -4)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1-5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "eac2f2d2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for  i in range(1,5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7c87e1a",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "\n",
    "* type(): 检查类型\n",
    "    \n",
    "> 1.数值\n",
    ">> 1.int\n",
    ">> 2.float\n",
    ">> 3complex\n",
    "\n",
    "> 2.字符串\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1492fe97",
   "metadata": {},
   "source": [
    "# 1.数值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8ceec2d",
   "metadata": {},
   "source": [
    "# 2.字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d6134306",
   "metadata": {},
   "outputs": [],
   "source": [
    "# complex(虚数)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b9192084",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = '''Alex'''\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a43caeac",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (Temp/ipykernel_9748/4008688494.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\11513\\AppData\\Local\\Temp/ipykernel_9748/4008688494.py\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    nfu_news_pages_html =\u001b[0m\n\u001b[1;37m                         ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "nfu_news_pages_html =\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "63c44d08",
   "metadata": {},
   "source": [
    "# 2.2关于字符串的方法及函数（https://docs.python.org/3/library/stdty.pes.html#text-sequence-type-str)\n",
    "\n",
    "* Single quotes: 'allows embedded \"double\" quotes'\n",
    "* Double quotes: \"allows embedded 'single' quotes\"\n",
    "* Triple quoted: \"Three single quotes\",\"\"\"Three double quotes\"\"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3e98b4b1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院广州市从化区温泉镇\n"
     ]
    }
   ],
   "source": [
    "# 关于有序性\n",
    "title = \"广州南方学院广州市从化区温泉镇\"\n",
    "print(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "f93f0856",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0] # 取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "2935003c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[1] # 取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "38cb5dd3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(title) # 检查文本的长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "71bef688",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'镇'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "0d8aaeb0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0:6] # 取一定范围的值，这种方法我们成为“切片”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "49222acb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4982f9e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "## enumerate 枚举，既可以获取到内容 item，又可以获取到索引值 index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "d30e76e4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广\n",
      "州\n",
      "南\n",
      "方\n",
      "学\n",
      "院\n",
      "广\n",
      "州\n",
      "市\n",
      "从\n",
      "化\n",
      "区\n",
      "温\n",
      "泉\n",
      "镇\n"
     ]
    }
   ],
   "source": [
    "## 利用for循环 遍历文本信息\n",
    "for i in title:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "b741d345",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考，如何判断一段文本中是否纯在“广州”\n",
    "for i,j in enumerate (title):\n",
    "    if j == \"广\":\n",
    "        if title[i+1]==\"洲\":\n",
    "            print(\"广州这个词在这段文本中\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "3e55814a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#in 检查成员对象\n",
    "\"广州\" in title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "ff63502e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好, 66\n"
     ]
    }
   ],
   "source": [
    "print(\"你好\" +\", \"+\"66\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "cd9249f2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 <class 'int'>\n",
      "1 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(1,type(1))\n",
    "print(\"1\",type(\"1\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "91615368",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 由于没有分清楚 字符串和数值的概念导致的“笑话”\n",
    "width = 16\n",
    "height = 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "7d7035ff",
   "metadata": {},
   "outputs": [],
   "source": [
    "面积 = width * height"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "0b3e86ec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "144"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "面积"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "309ab028",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院广州市从化区温泉镇'"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "796c5a9e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"新媒体\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "7d408432",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广州南方学院广州市从化区温泉镇']"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.split(\"坐落于\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb96a97b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
